package com.wwwarehouse.usercenter.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.wwwarehouse.common.bean.filter.FilterBean;
import com.wwwarehouse.usercenter.bean.business_relationship.BRCustomerFileListBean;

import java.util.List;

/**
 * 多选筛选器的Adapter
 * Created by ShineF on 2017/7/11 0011.
 */

public class FilterMultipleDoubleAdapter extends BaseAdapter {
    private Context mContext;
    private List<BRCustomerFileListBean.ScreeningTagsBean> mList;
    private List<BRCustomerFileListBean.ScreeningSalesMansBean> mList2;
    private ViewHolder mHolder;

    public FilterMultipleDoubleAdapter(Context context, List<BRCustomerFileListBean.ScreeningTagsBean> filterList, List<BRCustomerFileListBean.ScreeningSalesMansBean> filterList2) {
        this.mContext = context;
        this.mList = filterList;
        this.mList2 = filterList2;
    }

    @Override
    public int getCount() {
        if (mList != null)
            return mList.size();
        else
            return mList2.size();

    }

    @Override
    public Object getItem(int position) {
        if (mList != null)
            return mList.get(position);
        else
            return mList2.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, com.wwwarehouse.common.R.layout.item_drawer_filter_multiple, null);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        if (mList != null){
            final BRCustomerFileListBean.ScreeningTagsBean screeningTagsBean = mList.get(position);
            if (screeningTagsBean.isSelect()) {
                mHolder.mBtn.setSelected(true);
            } else {
                mHolder.mBtn.setSelected(false);
            }

            mHolder.mBtn.setText(screeningTagsBean.getTagName());
            mHolder.mBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    screeningTagsBean.setSelect(!screeningTagsBean.isSelect());

                    notifyDataSetChanged();
                }
            });
        }else{
            final BRCustomerFileListBean.ScreeningSalesMansBean screeningTagsBean = mList2.get(position);
            if (screeningTagsBean.isSelect()) {
                mHolder.mBtn.setSelected(true);
            } else {
                mHolder.mBtn.setSelected(false);
            }

            mHolder.mBtn.setText(screeningTagsBean.getSalesManName());
            mHolder.mBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    screeningTagsBean.setSelect(!screeningTagsBean.isSelect());

                    notifyDataSetChanged();
                }
            });

        }
        return convertView;
    }

    class ViewHolder {
        Button mBtn;

        public ViewHolder(View view) {
            mBtn = (Button) view.findViewById(com.wwwarehouse.common.R.id.btn_item);
        }
    }
}
